package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyCommunityDoorVo;
import com.ruoyi.system.bo.ZsyyCommunityDoorQueryBo;
import com.ruoyi.system.bo.ZsyyCommunityDoorAddBo;
import com.ruoyi.system.bo.ZsyyCommunityDoorEditBo;
import com.ruoyi.system.service.IZsyyCommunityDoorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 门禁状态管理Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "门禁状态管理控制器", tags = {"门禁状态管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/communityDoor")
public class ZsyyCommunityDoorController extends BaseController {

    private final IZsyyCommunityDoorService iZsyyCommunityDoorService;

    /**
     * 查询门禁状态管理列表
     */
    @ApiOperation("查询门禁状态管理列表")
    @PreAuthorize("@ss.hasPermi('system:communityDoor:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyCommunityDoorVo> list(@Validated ZsyyCommunityDoorQueryBo bo) {
        return iZsyyCommunityDoorService.queryPageList(bo);
    }

    /**
     * 导出门禁状态管理列表
     */
    @ApiOperation("导出门禁状态管理列表")
    @PreAuthorize("@ss.hasPermi('system:communityDoor:export')")
    @Log(title = "门禁状态管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyCommunityDoorVo> export(@Validated ZsyyCommunityDoorQueryBo bo) {
        List<ZsyyCommunityDoorVo> list = iZsyyCommunityDoorService.queryList(bo);
        ExcelUtil<ZsyyCommunityDoorVo> util = new ExcelUtil<ZsyyCommunityDoorVo>(ZsyyCommunityDoorVo.class);
        return util.exportExcel(list, "门禁状态管理");
    }

    /**
     * 获取门禁状态管理详细信息
     */
    @ApiOperation("获取门禁状态管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:communityDoor:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyCommunityDoorVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyCommunityDoorService.queryById(id));
    }

    /**
     * 新增门禁状态管理
     */
    @ApiOperation("新增门禁状态管理")
    @PreAuthorize("@ss.hasPermi('system:communityDoor:add')")
    @Log(title = "门禁状态管理", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyCommunityDoorAddBo bo) {
        return toAjax(iZsyyCommunityDoorService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改门禁状态管理
     */
    @ApiOperation("修改门禁状态管理")
    @PreAuthorize("@ss.hasPermi('system:communityDoor:edit')")
    @Log(title = "门禁状态管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyCommunityDoorEditBo bo) {
        return toAjax(iZsyyCommunityDoorService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除门禁状态管理
     */
    @ApiOperation("删除门禁状态管理")
    @PreAuthorize("@ss.hasPermi('system:communityDoor:remove')")
    @Log(title = "门禁状态管理" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyCommunityDoorService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
